<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>ports_profiler &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../_static/jquery.js?v=5d32c60e"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../_static/documentation_options.js?v=c8100655"></script>
        <script src="../_static/doctools.js?v=9a2dae69"></script>
        <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="profiler" href="profiler.html" />
    <link rel="prev" title="packs" href="packs.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../userman/index.html">User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../refman/index.html">Reference Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../faq/index.html">FAQ</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Developer Tools</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="overview.html">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="asdf.html"><code class="docutils literal notranslate"><span class="pre">asdf</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="assertions.html"><code class="docutils literal notranslate"><span class="pre">assertions</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="code_metrics.html"><code class="docutils literal notranslate"><span class="pre">code_metrics</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="dead_code_scanner.html"><code class="docutils literal notranslate"><span class="pre">dead_code_scanner</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="debug_messages.html"><code class="docutils literal notranslate"><span class="pre">debug_messages</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="debugger.html"><code class="docutils literal notranslate"><span class="pre">debugger</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="diagrams.html"><code class="docutils literal notranslate"><span class="pre">diagrams</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="doclet.html"><code class="docutils literal notranslate"><span class="pre">doclet</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="help.html"><code class="docutils literal notranslate"><span class="pre">help</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="issue_creator.html"><code class="docutils literal notranslate"><span class="pre">issue_creator</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="lgtdoc.html"><code class="docutils literal notranslate"><span class="pre">lgtdoc</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="lgtunit.html"><code class="docutils literal notranslate"><span class="pre">lgtunit</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="linter.html"><code class="docutils literal notranslate"><span class="pre">linter</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="make.html"><code class="docutils literal notranslate"><span class="pre">make</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="packs.html"><code class="docutils literal notranslate"><span class="pre">packs</span></code></a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#"><code class="docutils literal notranslate"><span class="pre">ports_profiler</span></code></a><ul>
<li class="toctree-l3"><a class="reference internal" href="#api-documentation">API documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="#loading">Loading</a></li>
<li class="toctree-l3"><a class="reference internal" href="#testing">Testing</a></li>
<li class="toctree-l3"><a class="reference internal" href="#compiling-source-files-for-port-profiling">Compiling source files for port profiling</a></li>
<li class="toctree-l3"><a class="reference internal" href="#generating-profiling-data">Generating profiling data</a></li>
<li class="toctree-l3"><a class="reference internal" href="#printing-profiling-data-reports">Printing profiling data reports</a></li>
<li class="toctree-l3"><a class="reference internal" href="#interpreting-profiling-data">Interpreting profiling data</a></li>
<li class="toctree-l3"><a class="reference internal" href="#profiling-prolog-modules">Profiling Prolog modules</a></li>
<li class="toctree-l3"><a class="reference internal" href="#profiling-plain-prolog-code">Profiling plain Prolog code</a></li>
<li class="toctree-l3"><a class="reference internal" href="#known-issues">Known issues</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="profiler.html"><code class="docutils literal notranslate"><span class="pre">profiler</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="tutor.html"><code class="docutils literal notranslate"><span class="pre">tutor</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="wrapper.html"><code class="docutils literal notranslate"><span class="pre">wrapper</span></code></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="index.html">Developer Tools</a></li>
      <li class="breadcrumb-item active"><code class="docutils literal notranslate"><span class="pre">ports_profiler</span></code></li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/devtools/ports_profiler.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="ports-profiler">
<span id="library-ports-profiler"></span><h1><code class="docutils literal notranslate"><span class="pre">ports_profiler</span></code><a class="headerlink" href="#ports-profiler" title="Link to this heading"></a></h1>
<p>This tool counts and reports the number of times each port in the
<em>procedure box model</em> is traversed during the execution of queries. It
can also report the number of times each clause (or grammar rule) is
used. It is inspired by the ECLiPSe <code class="docutils literal notranslate"><span class="pre">port_profiler</span></code> tool.</p>
<p>The procedure box model is the same as the one used in the debugger
tool. This is an extended version of the original Byrd’s four-port
model. Besides the standard <code class="docutils literal notranslate"><span class="pre">call</span></code>, <code class="docutils literal notranslate"><span class="pre">exit</span></code>, <code class="docutils literal notranslate"><span class="pre">fail</span></code>, and <code class="docutils literal notranslate"><span class="pre">redo</span></code>
ports, Logtalk also defines two post-unification ports, <code class="docutils literal notranslate"><span class="pre">fact</span></code> and
<code class="docutils literal notranslate"><span class="pre">rule</span></code>, and an <code class="docutils literal notranslate"><span class="pre">exception</span></code> port. This tool can also distinguish
between deterministic exits (reported in the <code class="docutils literal notranslate"><span class="pre">exit</span></code> column in the
profiling result tables) and exits that leave choice-points (reported in
the <code class="docutils literal notranslate"><span class="pre">*exit</span></code> column).</p>
<section id="api-documentation">
<h2>API documentation<a class="headerlink" href="#api-documentation" title="Link to this heading"></a></h2>
<p>This tool API documentation is available at:</p>
<p><a class="reference external" href="../../apis/library_index.html#ports-profiler">../../apis/library_index.html#ports-profiler</a></p>
<p>For sample queries, please see the <code class="docutils literal notranslate"><span class="pre">SCRIPT.txt</span></code> file in the tool
directory.</p>
</section>
<section id="loading">
<h2>Loading<a class="headerlink" href="#loading" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(ports_profiler(loader)).
</pre></div>
</div>
</section>
<section id="testing">
<h2>Testing<a class="headerlink" href="#testing" title="Link to this heading"></a></h2>
<p>To test this tool, load the <code class="docutils literal notranslate"><span class="pre">tester.lgt</span></code> file:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(ports_profiler(tester)).
</pre></div>
</div>
</section>
<section id="compiling-source-files-for-port-profiling">
<h2>Compiling source files for port profiling<a class="headerlink" href="#compiling-source-files-for-port-profiling" title="Link to this heading"></a></h2>
<p>To compile source files for port profiling, simply compile them in debug
mode and with the <code class="docutils literal notranslate"><span class="pre">source_data</span></code> flag turned on. For example:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(my_source_file, [debug(on), source_data(on)]).
</pre></div>
</div>
<p>Alternatively, you can also simply turn on the <code class="docutils literal notranslate"><span class="pre">debug</span></code> and
<code class="docutils literal notranslate"><span class="pre">source_data</span></code> flags globally before compiling your source files:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">set_logtalk_flag</span>(debug, on), <span class="k">set_logtalk_flag</span>(source_data, on).
</pre></div>
</div>
<p>Be aware, however, that loader files (e.g., library loader files) may
override the default flag values, and thus the loaded files may not be
compiled in debug mode. In this case, you will need to modify the loader
files themselves.</p>
</section>
<section id="generating-profiling-data">
<h2>Generating profiling data<a class="headerlink" href="#generating-profiling-data" title="Link to this heading"></a></h2>
<p>After loading this tool and compiling the source files that you want to
profile in debug mode, simply call the <code class="docutils literal notranslate"><span class="pre">ports_profiler::start</span></code> goal
followed by the goals to be profiled. Use the <code class="docutils literal notranslate"><span class="pre">ports_profiler::stop</span></code>
goal to stop profiling.</p>
<p>Note that the <code class="docutils literal notranslate"><span class="pre">ports_profiler::start/0</span></code> predicate implicitly selects
the <code class="docutils literal notranslate"><span class="pre">ports_profiler</span></code> tool as the active debug handler. If you have
additional debug handlers loaded (e.g., the <code class="docutils literal notranslate"><span class="pre">debugger</span></code> tool), those
would no longer be active (there can be only one active debug handler at
any given time).</p>
</section>
<section id="printing-profiling-data-reports">
<h2>Printing profiling data reports<a class="headerlink" href="#printing-profiling-data-reports" title="Link to this heading"></a></h2>
<p>After calling the goals that you want to profile, you can print a table
with all profile data by typing:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> ports_profiler<span class="o">::</span>data.
</pre></div>
</div>
<p>To print a table with data for a single entity, use the query:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> ports_profiler<span class="o">::</span>data(<span class="nv">Entity</span>).
</pre></div>
</div>
<p>To print a table with data for a single entity predicate, use the query:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> ports_profiler<span class="o">::</span>data(<span class="nv">Entity</span>, <span class="nv">Predicate</span>).
</pre></div>
</div>
<p>In this case, the second argument must be either a predicate indicator,
<code class="docutils literal notranslate"><span class="pre">Name/Arity</span></code>, or a non-terminal indicator, <code class="docutils literal notranslate"><span class="pre">Name//Arity</span></code>.</p>
<p>The profiling data can be reset using the query:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> ports_profiler<span class="o">::</span>reset.
</pre></div>
</div>
<p>To reset only the data for a specific entity, use the query:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> ports_profiler<span class="o">::</span>reset(<span class="nv">Entity</span>).
</pre></div>
</div>
<p>To illustrate the tool output, consider the <code class="docutils literal notranslate"><span class="pre">family</span></code> example in the
Logtalk distribution:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">{</span>ports_profiler(loader)<span class="k">}</span>.
...
yes

| <span class="o">?-</span> <span class="k">set_logtalk_flag</span>(debug, on).
yes

| <span class="o">?-</span> <span class="k">logtalk_load</span>(family(loader)).
...
yes

| <span class="o">?-</span> ports_profiler<span class="o">::</span>start.
yes

| <span class="o">?-</span> addams<span class="o">::</span>sister(<span class="nv">Sister</span>, <span class="nv">Sibling</span>).
<span class="nv">Sister</span> <span class="o">=</span> wednesday,
<span class="nv">Sibling</span> <span class="o">=</span> pubert <span class="o">;</span>
<span class="nv">Sister</span> <span class="o">=</span> wednesday,
<span class="nv">Sibling</span> <span class="o">=</span> pugsley <span class="o">;</span>
<span class="nv">Sister</span> <span class="o">=</span> wednesday,
<span class="nv">Sibling</span> <span class="o">=</span> pubert <span class="o">;</span>
<span class="nv">Sister</span> <span class="o">=</span> wednesday,
<span class="nv">Sibling</span> <span class="o">=</span> pugsley <span class="o">;</span>
no

| <span class="o">?-</span> ports_profiler<span class="o">::</span>data.
<span class="o">----------------------------------------------------------------------</span>
<span class="nv">Entity</span>     <span class="nv">Predicate</span>    <span class="nv">Fact</span>  <span class="nv">Rule</span>  <span class="nv">Call</span>  <span class="nv">Exit</span> <span class="o">*</span><span class="nv">Exit</span>  <span class="nv">Fail</span>  <span class="nv">Redo</span> <span class="nv">Error</span>
<span class="o">----------------------------------------------------------------------</span>
addams     female<span class="o">/</span><span class="m">1</span>        <span class="m">2</span>     <span class="m">0</span>     <span class="m">1</span>     <span class="m">1</span>     <span class="m">1</span>     <span class="m">0</span>     <span class="m">1</span>     <span class="m">0</span>
addams     parent<span class="o">/</span><span class="m">2</span>        <span class="m">8</span>     <span class="m">0</span>     <span class="m">4</span>     <span class="m">3</span>     <span class="m">5</span>     <span class="m">1</span>     <span class="m">5</span>     <span class="m">0</span>
relations  sister<span class="o">/</span><span class="m">2</span>        <span class="m">0</span>     <span class="m">1</span>     <span class="m">1</span>     <span class="m">0</span>     <span class="m">4</span>     <span class="m">1</span>     <span class="m">4</span>     <span class="m">0</span>
<span class="o">----------------------------------------------------------------------</span>
yes

| <span class="o">?-</span> ports_profiler<span class="o">::</span>data(addams).
<span class="o">-----------------------------------------------------------</span>
<span class="nv">Predicate</span>    <span class="nv">Fact</span>  <span class="nv">Rule</span>  <span class="nv">Call</span>  <span class="nv">Exit</span> <span class="o">*</span><span class="nv">Exit</span>  <span class="nv">Fail</span>  <span class="nv">Redo</span> <span class="nv">Error</span>
<span class="o">-----------------------------------------------------------</span>
female<span class="o">/</span><span class="m">1</span>        <span class="m">2</span>     <span class="m">0</span>     <span class="m">1</span>     <span class="m">1</span>     <span class="m">1</span>     <span class="m">0</span>     <span class="m">1</span>     <span class="m">0</span>
parent<span class="o">/</span><span class="m">2</span>        <span class="m">8</span>     <span class="m">0</span>     <span class="m">4</span>     <span class="m">3</span>     <span class="m">5</span>     <span class="m">1</span>     <span class="m">5</span>     <span class="m">0</span>
<span class="o">-----------------------------------------------------------</span>
yes

| <span class="o">?-</span> ports_profiler<span class="o">::</span>data(addams, parent<span class="o">/</span><span class="m">2</span>).
<span class="o">-------------</span>
<span class="nv">Clause</span>  <span class="nv">Count</span>
<span class="o">-------------</span>
     <span class="m">1</span>      <span class="m">1</span>
     <span class="m">2</span>      <span class="m">1</span>
     <span class="m">3</span>      <span class="m">2</span>
     <span class="m">4</span>      <span class="m">1</span>
     <span class="m">5</span>      <span class="m">1</span>
     <span class="m">6</span>      <span class="m">2</span>
<span class="o">-------------</span>
yes
</pre></div>
</div>
</section>
<section id="interpreting-profiling-data">
<h2>Interpreting profiling data<a class="headerlink" href="#interpreting-profiling-data" title="Link to this heading"></a></h2>
<p>Some useful information that can be inferred from the profiling data
include:</p>
<ul class="simple">
<li><p>which predicates are called more often (from the <code class="docutils literal notranslate"><span class="pre">call</span></code> port)</p></li>
<li><p>unexpected failures (from the <code class="docutils literal notranslate"><span class="pre">fail</span></code> port)</p></li>
<li><p>unwanted non-determinism (from the <code class="docutils literal notranslate"><span class="pre">*exit</span></code> port)</p></li>
<li><p>performance issues due to backtracking (from the <code class="docutils literal notranslate"><span class="pre">*exit</span></code> and
<code class="docutils literal notranslate"><span class="pre">redo</span></code> ports)</p></li>
<li><p>predicates acting like a generator of possible solutions (from the
<code class="docutils literal notranslate"><span class="pre">*exit</span></code> and <code class="docutils literal notranslate"><span class="pre">redo</span></code> ports)</p></li>
<li><p>inefficient indexing of predicate clauses (from the <code class="docutils literal notranslate"><span class="pre">fact</span></code>,
<code class="docutils literal notranslate"><span class="pre">rule</span></code>, and <code class="docutils literal notranslate"><span class="pre">call</span></code> ports)</p></li>
<li><p>clauses that are never used or seldom used</p></li>
</ul>
<p>The profiling data should be analyzed by taking into account the
expected behavior for the profiled predicates.</p>
</section>
<section id="profiling-prolog-modules">
<h2>Profiling Prolog modules<a class="headerlink" href="#profiling-prolog-modules" title="Link to this heading"></a></h2>
<p>This tool can also be applied to Prolog modules that Logtalk is able to
compile as objects. For example, if the Prolog module file is named
<code class="docutils literal notranslate"><span class="pre">module.pl</span></code>, try:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(module, [debug(on), source_data(on)]).
</pre></div>
</div>
<p>Due to the lack of standardization of module systems and the abundance
of proprietary extensions, this solution is not expected to work for all
cases.</p>
</section>
<section id="profiling-plain-prolog-code">
<h2>Profiling plain Prolog code<a class="headerlink" href="#profiling-plain-prolog-code" title="Link to this heading"></a></h2>
<p>This tool can also be applied to plain Prolog code. For example, if the
Prolog file is named <code class="docutils literal notranslate"><span class="pre">code.pl</span></code>, simply define an object including its
code and declaring as public any predicates that you want to use as
messages to the object. For example:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">object</span>(code).

<span class="p">    :- </span><span class="k">public</span>(foo<span class="o">/</span><span class="m">2</span>).
<span class="p">    :- </span><span class="k">include</span>(<span class="s">&#39;code.pl&#39;</span>).

<span class="p">:- </span><span class="k">end_object</span>.
</pre></div>
</div>
<p>Save the object to an e.g. <code class="docutils literal notranslate"><span class="pre">code.lgt</span></code> file in the same directory as
the Prolog file and then load it in debug mode:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(code, [debug(on), source_data(on)]).
</pre></div>
</div>
<p>In alternative, use the <code class="docutils literal notranslate"><span class="pre">object_wrapper_hook</span></code> provided by the
<code class="docutils literal notranslate"><span class="pre">hook_objects</span></code> library:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> <span class="k">logtalk_load</span>(hook_objects(loader)).
...

| <span class="o">?-</span> <span class="k">logtalk_load</span>(
         code,
         [hook(object_wrapper_hook), debug(on),
          source_data(on), context_switching_calls(allow)]
     ).
</pre></div>
</div>
<p>In this second alternative, you can then use the <code class="docutils literal notranslate"><span class="pre">(&lt;&lt;)/2</span></code> context
switch control construct to call the wrapped predicates. E.g.</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>| <span class="o">?-</span> code<span class="o">&lt;&lt;</span>foo(<span class="nv">X</span>, <span class="nv">Y</span>).
</pre></div>
</div>
<p>With either wrapping solution, pay special attention to any compilation
warnings that may signal issues that could prevent the plain Prolog code
from working as-is when wrapped by an object. Often any required changes
are straightforward (e.g., adding <code class="docutils literal notranslate"><span class="pre">use_module/2</span></code> directives for called
module library predicates).</p>
</section>
<section id="known-issues">
<h2>Known issues<a class="headerlink" href="#known-issues" title="Link to this heading"></a></h2>
<p>Determinism information is currently not available when using Quintus
Prolog as the backend compiler.</p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="packs.html" class="btn btn-neutral float-left" title="packs" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="profiler.html" class="btn btn-neutral float-right" title="profiler" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>